import { create, all } from './math.min.js';
const config = {
	epsilon: 1e-12,
	matrix: 'Matrix',
	number: 'number',
	precision: 64,
	predictable: false,
	randomSeed: null,
};
const math = create(all, config);
//开方
export function toNumberSqrt(arg1) {
	if (notEmpty(arg1)) {
		return math.sqrt(arg1);
		math.number(math.sqrt(math.bignumber(arg1)));
	} else {
		return undefined;
	}
}
//除
export function toNumberExcept(arg1, arg2) {
	if (notEmpty(arg1) && notEmpty(arg2)) {
		let price = math.number(
			math.divide(math.bignumber(arg1), math.bignumber(arg2)),
		);
		return isNaN(price) ? undefined : price;
	} else {
		return undefined;
	}
}
//乘
export function toNumberRide(arg1, arg2) {
	if (notEmpty(arg1) && notEmpty(arg2)) {
		let price = math.number(
			math.multiply(math.bignumber(arg1), math.bignumber(arg2)),
		);
		return isNaN(price) ? undefined : price;
	} else {
		return undefined;
	}
}

//加
export function toNumberAdd(arg1, arg2) {
	if (Empty(arg1) && Empty(arg2)) {
		return undefined;
	}
	if (notEmpty(arg1) || notEmpty(arg2)) {
		let price = math.number(
			math.add(math.bignumber(arg1 ?? 0), math.bignumber(arg2 ?? 0)),
		);
		return isNaN(price) ? undefined : price;
	} else {
		return undefined;
	}
}
//减
export function toNumberSub(arg1, arg2) {
	if (Empty(arg1) && Empty(arg2)) {
		return undefined;
	}
	if (notEmpty(arg1) || notEmpty(arg2)) {
		let price = math.number(
			math.subtract(math.bignumber(arg1 ?? 0), math.bignumber(arg2 ?? 0)),
		);
		return isNaN(price) ? undefined : price;
	} else {
		return undefined;
	}
}
export function notEmpty(value) {
	let result = true;
	if (value === undefined || value === null || value === '') {
		result = false;
	} else {
		result = true;
	}
	if (Object.prototype.toString.call(value) === '[object Array]') {
		if (value.length == 0) {
			result = false;
		} else {
			result = true;
		}
	}
	if (Object.prototype.toString.call(value) === '[object Object]') {
		if (Object.keys(value).length == 0) {
			result = false;
		} else {
			result = true;
		}
	}
	return result;
}
export function Empty(value) {
	let result = true;
	if (value === undefined || value === null || value === '') {
		result = true;
	} else {
		result = false;
	}
	if (Object.prototype.toString.call(value) === '[object Array]') {
		if (value.length == 0) {
			result = true;
		} else {
			result = false;
		}
	}
	if (Object.prototype.toString.call(value) === '[object Object]') {
		if (Object.keys(value).length == 0) {
			result = true;
		} else {
			result = false;
		}
	}
	return result;
}
